package com.zyong.encryption.server.controller;

import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import com.netflix.eureka.EurekaServerContextHolder;
import com.zyong.encryption.server.config.NettyConfig;
import com.zyong.encryption.server.socket.SocketManager;
import com.zyong.encryption.server.entity.NettyManagerInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * TxManagerIndexController.
 * @author xiaoyu
 */
@Controller
public class EncryptionServerIndexController {
    @Autowired
    private NettyConfig nettyConfig;

    @RequestMapping("/index")
    public String index(final HttpServletRequest request) {
        NettyManagerInfo txManagerInfo = new NettyManagerInfo();
        //设置ip为eureka 上注册的TxManager ip
        String ip = EurekaServerContextHolder.getInstance().getServerContext().getApplicationInfoManager()
                                                           .getEurekaInstanceConfig().getIpAddress();
        txManagerInfo.setIp(ip);
        txManagerInfo.setPort(nettyConfig.getPort());
        txManagerInfo.setMaxConnection(SocketManager.getInstance().getMaxConnection());
        txManagerInfo.setNowConnection(SocketManager.getInstance().getNowConnection());
        
        request.setAttribute("info", txManagerInfo);
        return "index";
    }

}
